package Blog1;

import java.util.Scanner;

public class Blog12 {
    public static void main(String[] args) {
        StringBuilder stringBuilder = new StringBuilder();
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("a");

        for (int i = 0; i < 10; i++) {
            stringBuilder.append("a");
        }

        System.out.println(stringBuilder.append("a"));
    }

    public static void main16(String[] args) {
        String str = "";

        for (int i = 0; i < 10; i++) {
            str += "a";
        }
        System.out.println(str);
    }

    public static void main15(String[] args) {
        String str = "abcdefg";
        System.out.println(str);
        String ret = dans(str,3);
        System.out.println(ret);
    }

    public static String dans(String str, int n) {
        if(null == str || n <= 0 || n >= str.length()) {
            return null;
        }
        str = reverse(str,0,n-1);
        str = reverse(str,n,str.length()-1);
        str = reverse(str,0,str.length()-1);
        return str;
    }

    public static String reverse(String str, int begin, int end) {
        char[] value = str.toCharArray();   // 将字符串转为字节char[]数组,
        // 一个一个字符，取出后替换，
        while(begin < end) {
            char tmp = value[begin];
            value[begin] = value[end];
            value[end] = tmp;
            begin++;
            end--;
        }

        return new String(value);  // 字符数组构造方法，创建字符串

      /* // 或者使用 String.copyValueOf() 将数组转为字符串返回
        return String.copyValueOf(value);
*/
    }



    public static void main14(String[] args) {
        String str = "hello world";
        int[] arrays = {1,2,3};

        System.out.println(str.length());
        System.out.println(arrays.length);
    }


    public static void main13(String[] args) {
        String  str = "hello";
        String str2 = "";

        System.out.println(str.isEmpty());
        System.out.println(str2.isEmpty());
    }

    public static void main12(String[] args) {
        String str = "aaaAAA你好世界!!!";
        String ret = str.toLowerCase();  // 大写转小写
        System.out.println(ret);
        String ret2 = str.toUpperCase();  // 小写转大写
        System.out.println(ret2);

    }


    public static String func(String str) {
        String[] strings = str.split(" ");
        String tmp = "";
        for (String s:strings) {
            tmp += s;
        }

        return tmp;
    }

    public static void main11(String[] args) {
        Scanner scanner = new Scanner(System.in);

        while(scanner.hasNext()) {
            String str = scanner.nextLine();
            // 不可以使用next()，因为读取到空格就结束了，
            // nextLine(), 不可以于 nextInt()连接使用，nextLine()会读取到回车
            String ret = func(str);
            System.out.println(ret);
        }
    }



    public static void main10(String[] args) {
        String str = "Java-split#18";
        String[] strings = str.split("-"); // 第一个拆分符号
        for (String s:strings) {
            String[] strings1 = s.split("#");  //# 第二个拆分符号，不是特殊符号，不用 \\

            for (String tmp: strings1){
                System.out.println(tmp);
            }
        }
    }


    public static void main9(String[] args) {
        String str = "192\\168\\1\\1";
        String[] strings = str.split("\\\\");

        for (String s:strings) {
            System.out.println(s);
        }
    }


    // 以空格为分隔标准
    public static void main8(String[] args) {
        String str = "hello world !!!";
        String[] strings = str.split("AA");

        for (String s: strings) {
            System.out.println(s);
        }

    }


    public static void main7(String[] args) {
        String str = "helloworld";
        boolean flg = str.endsWith("world");
        boolean flg2 = str.endsWith("hello");
        System.out.println(flg);
        System.out.println(flg2);
    }

    public static void main6(String[] args) {
        String str = "helloworld";
        boolean flg = str.startsWith("hello",0);
        boolean flg2 = str.startsWith("hello",6);
        System.out.println(flg);
        System.out.println(flg2);
    }


    public static void main5(String[] args) {
        String str = "helloworld";
        boolean flg = str.startsWith("hello");
        boolean flg2 = str.startsWith("world");
        System.out.println(flg);
        System.out.println(flg2);
    }


    public static void main4(String[] args) {
        String str = "helloworld";
        int flg = str.lastIndexOf("world");
        int flg2 = str.lastIndexOf("hi");
        System.out.println(flg);
        System.out.println(flg2);

        int flg3 = str.lastIndexOf("world",9); // 从后向前，指定位置开始查找
        System.out.println(flg3);
    }


    public static void main3(String[] args) {
        String str = "helloworld";
        int flg = str.indexOf("world",3);
        int flg2 = str.indexOf("hi",0);
        System.out.println(flg);
        System.out.println(flg2);
    }

    public static void main2(String[] args) {
        String str = "helloworld";
        int flg = str.indexOf("world");
        int flg2 = str.indexOf("hi");
        System.out.println(flg);
        System.out.println(flg2);
    }




    public static void main1(String[] args) {
        String str = "hello world";
        boolean flg = str.contains("hello");
        System.out.println(flg);
        boolean flg2 = str.contains("Hi");
        System.out.println(flg2);
    }
}
